package bpm.dao.impl.demo;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;

import bpm.dao.demo.DemoDao;
import bpm.domain.demo.Demo;

@Repository("demoDao")
public class DemoDaoImpl implements DemoDao {
	@Resource
	private JdbcTemplate jdbcTemplate;
	
	public void delete(String id) {
		String sql = "delete from demo where id=?";
		
		Object[] args = new Object[]{id};
	
		this.jdbcTemplate.update(sql, args);
	}

	public Demo find(String id) {
		String sql = "select id,name from demo where id=?";
		
		Object[] args = new Object[]{id};
	
		return (Demo)this.jdbcTemplate.queryForObject(sql, args, new DemoMapper());
	}

	public void merge(Demo demo) {
		String sql = "update demo set name=? where id=?";
		
		Object[] args = new Object[]{demo.getName(), demo.getId()};
	
		this.jdbcTemplate.update(sql, args);
	}

	public void persist(Demo demo) {
		String sql = "insert into demo(id,name) values(?,?)";
		
		Object[] args = new Object[]{demo.getId(), demo.getName()};
	
		this.jdbcTemplate.update(sql, args);
	}
	@SuppressWarnings("unchecked")
	public List<Demo> findResultList() {
		String sql = "select id,name from demo";
		
		return this.jdbcTemplate.query(sql, new DemoMapper());
	}

}
